package com.liu.SocketTcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 服务端
 * 字节流
 */
public class SocketTcp01 {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        int readLen = 0;
        byte[] bytes = new byte[1024];
        while((readLen = inputStream.read(bytes)) != -1) {
            System.out.println(new String(bytes, 0, readLen));
        }
        socket.shutdownInput();
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("Hello client".getBytes());
        socket.shutdownOutput();
        outputStream.close();
        serverSocket.close();
        socket.close();
        inputStream.close();
    }
}
